<!-- eslint-disable no-undef -->
<script setup lang="ts">
import DoctorCard from './DoctorCard.vue'
import { useWindowSize } from '@vueuse/core'
import { getDoctorList } from '@/services/consult'
import type { DoctorList } from '@/types/consult'
const { width } = useWindowSize()
/* const width = ref(0)
console.log(window.innerWidth)
const setWidth = () => (width.value = window.innerWidth)
// dom挂载完毕后 设置width的宽度
onMounted(() => {
  setWidth()
})
// 窗口发生变化后 设置width的宽度
window.addEventListener('resize', setWidth)
// 组件销毁后, 移除全局的事件
onUnmounted(() => window.removeEventListener('resize', setWidth)) */
const doctorList = ref<DoctorList>([])
// 获取医生列表
const getList = async () => {
  const res = await getDoctorList({ current: 1, pageSize: 10 })
  doctorList.value = res.data.rows
}
getList()
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注 {{ width }}</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件 -->
      <van-swipe
        :width="(150 / 375) * width"
        :loop="false"
        :show-indicators="false"
      >
        <van-swipe-item v-for="item in doctorList" :key="item.id">
          <DoctorCard :item="item"></DoctorCard>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>
